/*
 * Author: Alberto De Pena
 * Applied Algorithms
 * bowling.cpp
*/

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int Convert(char x)
{
    int num;
    if(x == 'X')
    {
        num = 10;
    }
    else if(x == '/')
    {
        num = 10;
    }
    else if(x >= '0' && x <= '9')
    {
        num = (int)x - 48;
    }
    else
    {
        num = -1;
    }
    return num;
}

int totalScore(int scorecard[])
{
    int score = 0;
    for(int r = 0; r < 10; r++)
    {
        score += scorecard[r];
    }
    return score;
}


void main()
{
    ifstream fin;
    ofstream fout;

	fin.open("bowling.in");
    fout.open("bowling.out");

    string line;

    int scorecard[10], b1, b2, b3, pos, score, rounds;
    bool validcard;
    
    getline( fin, line );
    while( line != "*" )
    {
        validcard = true;
        pos = 0;
        for( rounds = 0; rounds < 10 && validcard == true; rounds++ )
        {
            b1 = line[pos];
            pos++;
            if( b1 == 'X' || b1 == '/' )
            {
                if( b1 == '/' )
                {
                    validcard = false;
                }
                else
                {
                    b2 = Convert( line[pos] );
                    if( b2 >= 0 )
                    {
                        b3 = line[pos+1];
                        if( b3 == '/' )
                        {
                            scorecard[rounds] = 20;
                        }
                        else if ( b3 >= '0' && b3 <= '9' || b3 == 'X' )
                        {
                            b3 = Convert( line[pos+1] );
                            scorecard[rounds] = 10 + b2 + b3;
                            if( b2 < 10 && b2 + b3 >= 10 )
                            {
                                validcard = false;
                            }
                        }
                        else
                        {
                            validcard = false;
                        }
                    }
                    else
                    {
                        validcard = false;
                    }
                }
            }
            else
            {
                b2 = line[pos];
                pos++;
                if( b2 == '/' )
                {
                    b3 = Convert( line[pos] );
                    scorecard[rounds] = 10 + b3;
                }
                else if ( b2 >= '0' && b2 <= '9' )
                {
                    b1 = Convert( b1 );
                    b2 = Convert( b2 );
                    if( b1 + b2 < 10 )
                    {
                        scorecard[rounds] = b1 + b2;
                    }
                    else
                    {
                        validcard = false;
                    }
                }
                else
                {
                    validcard = false;
                }
            }

        }
        
        int length = line.length();
        char frame10 = line[pos-1];

        if( frame10 == 'X' )
        {
            if( length != pos + 2 )
                validcard = false;
        }
        else if( frame10 == '/' )
        {
            if( length != pos + 1 )
                validcard = false;
        }
        else
        {
            if( length != pos )
                validcard = false;
        }

        if( validcard )
        {
            fout << totalScore( scorecard ) << endl;
        }
        else
        {
            fout << "INVALID" << endl;
        }
        getline( fin, line );
    }

    fin.close();
    fout.close();
}

